﻿using Newtonsoft.Json;
using PhysicalExamination5.Interface.DataMaintenance;
using PhysicalExamination5.Model.DataMaintenance;
using PhysicalExamination5.Model.PhysicalExamination;
using PhysicalExamination5.Model.SystemSetting;
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http.Headers;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static Npgsql.Replication.PgOutput.Messages.RelationMessage;

namespace PhysicalExamination5.Service.DataMaintenance
{
    public class SWeiHaiYinSuWeiHu : IWeiHaiYinSuWeiHu
    {
        private readonly ISqlSugarClient db;
        public SWeiHaiYinSuWeiHu(ISqlSugarClient db)
        {
            this.db = db;
        }
        /// <summary>
        /// 查询全部组合项目
        /// </summary>
        /// <returns></returns>
        public string GetSelItemAll()
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");


                List<jcsj_ZuHeXiangMu> listjcsj_ZuHeXiangMu = new SqlSugarRepository<jcsj_ZuHeXiangMu>(db).getAll();


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = listjcsj_ZuHeXiangMu
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 查询危害因素
        /// </summary>
        /// <param name="strZhongLei"></param>
        /// <param name="strName"></param>
        /// <returns></returns>
        public string GetSelWeiHaiYinSu(string strZhongLei, string strName)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                List<jcsj_WeiHaiYinSu> listjcsj_WeiHaiYinSu = new List<jcsj_WeiHaiYinSu>();

                #endregion

                #region 查询数据

                if (string.IsNullOrEmpty(strName))
                {
                    listjcsj_WeiHaiYinSu = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuZhongLei == strZhongLei).OrderBy(t => t.ShunXu).ToList();
                }
                else
                {
                    listjcsj_WeiHaiYinSu = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db)
                        .getByWhere(t => t.WeiHaiYinSuZhongLei == strZhongLei && t.WeiHaiYinSuMingCheng.Contains(strName)
                        || t.PYM.Contains(strName)).OrderBy(t => t.ShunXu).ToList();
                }


            #endregion

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = listjcsj_WeiHaiYinSu
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 查询危害因素项目、检查内容、监护依据、国标内容
        /// </summary>
        /// <param name="strWeiHaiYinSuId"></param>
        /// <param name="strGangQi"></param>
        /// <param name="strWeiHaiYinSuGuoBiaoDaiMa"></param>
        /// <returns></returns>
        public string GetSelWeiHaiYinSuData(string strWeiHaiYinSuId, string strGangQi, string strWeiHaiYinSuGuoBiaoDaiMa)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                object WeiHaiYinSuItem = null;
                object WeiHaiYinSuJianChaNeiRong = null;
                object WeiHaiYinSuJianHuYiJu = null;
                object WeiHaiYinSuGuoBiaoXiangMu = null;

                WeiHaiYinSuItem = new SqlSugarRepository<object>(db).getListBySql($@"select A.*,B.ZuHeXiangMuMingCheng,B.GuoBiaoDaiMa from jcsj_WeiHaiYinSuZuHeXiangMu A with(nolock),jcsj_ZuHeXiangMu B with(nolock) where A.ZuHeXiangMuID = B.ZuHeXiangMuID
and WeiHaiYinSuID = '{strWeiHaiYinSuId}'
and GangQi = '{strGangQi}'
order by ShunXu");
                WeiHaiYinSuJianChaNeiRong = new
                {
                    JianChaNeiRong = new SqlSugarRepository<jcsj_WeiHaiYinSuJianChaNeiRong>(db).getByWhere(t => t.WeiHaiYinSuID == strWeiHaiYinSuId && t.GangQi == strGangQi).Select(t => t.JianChaNeiRong).FirstOrDefault(),
                    MuBiaoJiBing = new SqlSugarRepository<jcsj_WeiHaiYinSuMuBiaoJiBing>(db).getByWhere(t => t.WeiHaiYinSuID == strWeiHaiYinSuId && t.GangQi == strGangQi).Select(t => t.MuBiaoJiBing).FirstOrDefault()
                };
                WeiHaiYinSuJianHuYiJu = new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).getByWhere(t => t.WeiHaiYinSuID == strWeiHaiYinSuId).OrderBy(t => t.ShunXu).ToList();
                WeiHaiYinSuGuoBiaoXiangMu = new SqlSugarRepository<GBZ_WeiHaiYinSuXiangMu>(db).getByWhere(t => t.WeiHaiYinSuBianMa == strWeiHaiYinSuGuoBiaoDaiMa).ToList();

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = new
                    {
                        WeiHaiYinSuItem,
                        WeiHaiYinSuJianChaNeiRong,
                        WeiHaiYinSuJianHuYiJu,
                        WeiHaiYinSuGuoBiaoXiangMu
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 查询国标对应的本地组合项目
        /// </summary>
        /// <param name="strGuoBiaoZuHeXiangMuDaiMa"></param>
        /// <returns></returns>
        public string GetSelGuoBiaoDuiYinItem(string strGuoBiaoZuHeXiangMuDaiMa)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                object Data = new SqlSugarRepository<object>(db).getListBySqlQuery($@"select B.ZuHeXiangMuID,B.ZuHeXiangMuMingCheng from GBZ_GuoBiaoDuiYingBenDi A with(nolock),jcsj_ZuHeXiangMu B with(nolock)
where A.BenDuiZuHeXiangMuID = B.ZuHeXiangMuID and A.GuoBiaoZuHeXiangMuDaiMa = '{strGuoBiaoZuHeXiangMuDaiMa}'");


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 新增危害因素
        /// </summary>
        /// <param name="WeiHaiYinSu"></param>
        /// <param name="strYuanQuQianZhui"></param>
        /// <returns></returns>
        public string PostWeiHaiYinSuAdd(WeiHaiYinSuClass WeiHaiYinSu, string strYuanQuQianZhui)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                int iShunXu;
                int itid;
                object Data = null;

                #endregion

                #region 验证数据

                if (!WeiHaiYinSu.Validate("Add", out strFanHuiZhi)) goto PROC_EXIT;
                if (new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuMingCheng == WeiHaiYinSu.strWeiHaiYinSuMingCheng).Any())
                {
                    nret = 1;
                    strFanHuiZhi = $@"当前危害因素【{WeiHaiYinSu.strWeiHaiYinSuMingCheng}】已经存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行添加

                DbResult<bool> result = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).UseTran(() =>
                {
                    var ShunXu = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuZhongLei == WeiHaiYinSu.strWeiHaiYinSuZhongLei);
                    if (ShunXu.Any())
                    {
                        iShunXu = ShunXu.Max(t => t.ShunXu) + 1;
                    }
                    else
                    {
                        iShunXu = 1;
                    }
                    jcsj_WeiHaiYinSu jcsj_WeiHaiYinSu = new jcsj_WeiHaiYinSu();
                    jcsj_WeiHaiYinSu.WeiHaiYinSuMingCheng = WeiHaiYinSu.strWeiHaiYinSuMingCheng;
                    jcsj_WeiHaiYinSu.GuoBiaoDaiMa = WeiHaiYinSu.strGuoBiaoDaiMa;
                    jcsj_WeiHaiYinSu.PYM = WeiHaiYinSu.strPym;
                    jcsj_WeiHaiYinSu.SuoShuYuanQu = WeiHaiYinSu.strSuoShuYuanQu;
                    jcsj_WeiHaiYinSu.WeiHaiYinSuZhongLei = WeiHaiYinSu.strWeiHaiYinSuZhongLei;
                    jcsj_WeiHaiYinSu.ShunXu = iShunXu;
                    itid = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).AddReturnIdentity(jcsj_WeiHaiYinSu);
                    if (!new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).Update(t => new jcsj_WeiHaiYinSu
                    {
                        WeiHaiYinSuID = strYuanQuQianZhui + itid
                    },t => t.tid == itid))
                    {
                        nret = 1000;
                        strFanHuiZhi = "保存危害因素失败！";
                        return;
                    }
                    jcsj_WeiHaiYinSu.WeiHaiYinSuID = strYuanQuQianZhui + itid;
                    Data = jcsj_WeiHaiYinSu;
                },
                 (ex) =>
                 {
                     nret = 1000;
                     strFanHuiZhi = ex.Message;
                     Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:事务报错异常:【{ex.Message}】");
                 });

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 修改危害因素
        /// </summary>
        /// <param name="WeiHaiYinSu"></param>
        /// <returns></returns>
        public string PutWeiHaiYinSuUpdate(WeiHaiYinSuClass WeiHaiYinSu)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                string strSql = "";
                object Data = null;

                #endregion

                #region 验证数据

                if (!WeiHaiYinSu.Validate("Update", out strFanHuiZhi)) goto PROC_EXIT;
                if (new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuMingCheng == WeiHaiYinSu.strWeiHaiYinSuMingCheng
                && t.WeiHaiYinSuID != WeiHaiYinSu.strWeiHaiYinSuId).Any())
                {
                    nret = 1;
                    strFanHuiZhi = $@"危害因素名称【{WeiHaiYinSu.strWeiHaiYinSuMingCheng}】已存在";
                    goto PROC_EXIT;
                }
                #endregion

                #region 修改

                strSql = $@"update jcsj_WeiHaiYinSu set WeiHaiYinSuMingCheng = '{WeiHaiYinSu.strWeiHaiYinSuMingCheng}',PYM = '{WeiHaiYinSu.strPym}'
,GuoBiaoDaiMa = '{WeiHaiYinSu.strGuoBiaoDaiMa}', SuoShuYuanQu = '{WeiHaiYinSu.strSuoShuYuanQu}'
where WeiHaiYinSuID = '{WeiHaiYinSu.strWeiHaiYinSuId}'";
                if (new SqlSugarRepository<object>(db).ExecuteCommandSql(strSql) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改失败！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 返回数据

                Data = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuID == WeiHaiYinSu.strWeiHaiYinSuId)[0];

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 删除危害因素
        /// </summary>
        /// <param name="deleteWeiHaiYinSu"></param>
        /// <returns></returns>
        public string DeleteWeiHaiYinSuDelete(DeleteWeiHaiYinSuClass deleteWeiHaiYinSu)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 验证数据

                if (!deleteWeiHaiYinSu.Validate(out strFanHuiZhi)) goto PROC_EXIT;

                #endregion

                #region 执行删除操作

                if (new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).DeleteWhere(t => t.WeiHaiYinSuID == deleteWeiHaiYinSu.strWeiHaiYinSuId) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "删除失败！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).DeleteWhere(t => t.WeiHaiYinSuID == deleteWeiHaiYinSu.strWeiHaiYinSuId) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "删除失败！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).DeleteWhere(t => t.WeiHaiYinSuID == deleteWeiHaiYinSu.strWeiHaiYinSuId) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "删除失败！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).Update(t => new jcsj_WeiHaiYinSu
                {
                    ShunXu = t.ShunXu - 1
                }, t => t.ShunXu > deleteWeiHaiYinSu.iShunXu) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = $@"修改失败！";
                    goto PROC_EXIT;
                }

            #endregion

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 调整危害因素顺序
        /// </summary>
        /// <param name="weiHaiYinSuShunXu"></param>
        /// <returns></returns>
        public string PutWeiHaiYinSunTiaoZhengShunXu(WeiHaiYinSuShunXuClass weiHaiYinSuShunXu)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                Expression<Func<jcsj_WeiHaiYinSu, jcsj_WeiHaiYinSu>> columns;
                Expression<Func<jcsj_WeiHaiYinSu, bool>> expression;

                #endregion

                #region 修改顺序

                if (new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).Update(t => new jcsj_WeiHaiYinSu
                {
                    ShunXu = weiHaiYinSuShunXu.iTiaoZhengHouShunXu
                }, t => t.WeiHaiYinSuID == weiHaiYinSuShunXu.strWeiHaiYinSuId) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改顺序失败！";
                    goto PROC_EXIT;
                }
                if (weiHaiYinSuShunXu.iTiaoZhengQianShunXu < weiHaiYinSuShunXu.iTiaoZhengHouShunXu)
                {
                    columns = t => new jcsj_WeiHaiYinSu
                    {
                        ShunXu = t.ShunXu - 1
                    };
                    expression = t => t.ShunXu >= weiHaiYinSuShunXu.iTiaoZhengQianShunXu && t.ShunXu <= weiHaiYinSuShunXu.iTiaoZhengHouShunXu
                    && t.WeiHaiYinSuID != weiHaiYinSuShunXu.strWeiHaiYinSuId && t.WeiHaiYinSuZhongLei == weiHaiYinSuShunXu.strZhongLei;
                }
                else if (weiHaiYinSuShunXu.iTiaoZhengQianShunXu > weiHaiYinSuShunXu.iTiaoZhengHouShunXu)
                {
                    columns = t => new jcsj_WeiHaiYinSu
                    {
                        ShunXu = t.ShunXu + 1
                    };
                    expression = t => t.ShunXu <= weiHaiYinSuShunXu.iTiaoZhengQianShunXu && t.ShunXu >= weiHaiYinSuShunXu.iTiaoZhengHouShunXu
                    && t.WeiHaiYinSuID != weiHaiYinSuShunXu.strWeiHaiYinSuId && t.WeiHaiYinSuZhongLei == weiHaiYinSuShunXu.strZhongLei;
                }
                else
                {
                    nret = 1;
                    strFanHuiZhi = "调整前后顺序一致！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).Update(columns, expression) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改顺序失败！";
                    goto PROC_EXIT;
                }

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素另存
        /// </summary>
        /// <param name="weiHaiYinSuLingCun"></param>
        /// <param name="strYuanQuQianZhui"></param>
        /// <returns></returns>
        public string PostWeiHaiYinSuLingCun(WeiHaiYinSuLingCunClass weiHaiYinSuLingCun, string strYuanQuQianZhui)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                List<string> listGangQi = new List<string>()
                {
                    "上岗前","在岗期间","离岗时","离岗后","应急"
                };
                List<jcsj_WeiHaiYinSu> listjcsj_WeiHaiYinSu = new List<jcsj_WeiHaiYinSu>();
                jcsj_WeiHaiYinSu jcsj_WeiHaiYinSu = new jcsj_WeiHaiYinSu();
                int iShunXu = 0;
                int itid = 0;
                string strSql = "";
                object Data = null;

                #endregion

                #region 验证数据

                listjcsj_WeiHaiYinSu = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuLingCun.strWeiHaiYinSuId);
                if (listjcsj_WeiHaiYinSu.Any() == false)
                {
                    nret = 1;
                    strFanHuiZhi = $@"未查询到危害因素Id为【{weiHaiYinSuLingCun.strWeiHaiYinSuId}】的记录！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuMingCheng == weiHaiYinSuLingCun.strLingCunMingCheng).Any())
                {
                    nret = 1;
                    strFanHuiZhi = $@"当前危害因素【{weiHaiYinSuLingCun.strLingCunMingCheng}】已经存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 危害因素

                jcsj_WeiHaiYinSu = listjcsj_WeiHaiYinSu[0];
                jcsj_WeiHaiYinSu.WeiHaiYinSuMingCheng = weiHaiYinSuLingCun.strLingCunMingCheng;
                jcsj_WeiHaiYinSu.PYM = new MethodHelper(db).ToFirstPinyin(weiHaiYinSuLingCun.strLingCunMingCheng);
                var ShunXu = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getByWhere(t => t.WeiHaiYinSuZhongLei == jcsj_WeiHaiYinSu.WeiHaiYinSuZhongLei);
                if (ShunXu.Any())
                {
                    iShunXu = ShunXu.Max(t => t.ShunXu) + 1;
                }
                else
                {
                    iShunXu = 1;
                }
                jcsj_WeiHaiYinSu.ShunXu = iShunXu;
                itid = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).AddReturnIdentity(jcsj_WeiHaiYinSu);
                jcsj_WeiHaiYinSu.WeiHaiYinSuID = strYuanQuQianZhui + itid;
                strSql = $"update jcsj_WeiHaiYinSu set WeiHaiYinSuID='{jcsj_WeiHaiYinSu.WeiHaiYinSuID}' where tid='{itid}'";
                if (new SqlSugarRepository<object>(db).ExecuteCommandSql(strSql) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "另存危害因素失败！";
                    goto PROC_EXIT;
                }

                #endregion


                foreach (var GangQi in listGangQi)
                {
                    #region 危害因素项目

                    List<jcsj_WeiHaiYinSuZuHeXiangMu> listjcsj_WeiHaiYinSuZuHeXiangMu = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db)
                   .getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuLingCun.strWeiHaiYinSuId && t.GangQi == GangQi);
                    if (listjcsj_WeiHaiYinSuZuHeXiangMu.Any())
                    {
                        listjcsj_WeiHaiYinSuZuHeXiangMu.ForEach(t =>
                        {
                            t.WeiHaiYinSuID = jcsj_WeiHaiYinSu.WeiHaiYinSuID;
                            t.GangQi = GangQi;
                        });
                        if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).AddRange(listjcsj_WeiHaiYinSuZuHeXiangMu) == false)
                        {
                            nret = 1000;
                            strFanHuiZhi = "另存危害因素项目失败！";
                            goto PROC_EXIT;
                        }
                    }

                    #endregion

                    #region 危害因素检查内容

                    List<jcsj_WeiHaiYinSuJianChaNeiRong> listjcsj_WeiHaiYinSuJianChaNeiRong = new SqlSugarRepository<jcsj_WeiHaiYinSuJianChaNeiRong>(db)
                        .getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuLingCun.strWeiHaiYinSuId && t.GangQi == GangQi);
                    if (listjcsj_WeiHaiYinSuJianChaNeiRong.Any())
                    {
                        listjcsj_WeiHaiYinSuJianChaNeiRong[0].WeiHaiYinSuID = jcsj_WeiHaiYinSu.WeiHaiYinSuID;
                        listjcsj_WeiHaiYinSuJianChaNeiRong[0].GangQi = GangQi;
                        if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianChaNeiRong>(db).Add(listjcsj_WeiHaiYinSuJianChaNeiRong[0]) == false)
                        {
                            nret = 1000;
                            strFanHuiZhi = "另存危害因素检查内容失败！";
                            goto PROC_EXIT;
                        }
                    }

                    #endregion

                    #region 危害因素目标疾病

                    List<jcsj_WeiHaiYinSuMuBiaoJiBing> listjcsj_WeiHaiYinSuMuBiaoJiBing = new SqlSugarRepository<jcsj_WeiHaiYinSuMuBiaoJiBing>(db)
                        .getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuLingCun.strWeiHaiYinSuId && t.GangQi == GangQi);
                    if (listjcsj_WeiHaiYinSuMuBiaoJiBing.Any())
                    {
                        listjcsj_WeiHaiYinSuMuBiaoJiBing[0].WeiHaiYinSuID = jcsj_WeiHaiYinSu.WeiHaiYinSuID;
                        listjcsj_WeiHaiYinSuMuBiaoJiBing[0].GangQi = GangQi;
                        if (new SqlSugarRepository<jcsj_WeiHaiYinSuMuBiaoJiBing>(db).Add(listjcsj_WeiHaiYinSuMuBiaoJiBing[0]) == false)
                        {
                            nret = 1000;
                            strFanHuiZhi = "另存危害因目标疾病失败！";
                            goto PROC_EXIT;
                        }
                    }

                    #endregion

                }

                #region 危害因素监护依据

                List<jcsj_WeiHaiYinSuJianHuYiJu> listjcsj_WeiHaiYinSuJianHuYiJu = new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db)
                    .getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuLingCun.strWeiHaiYinSuId);
                if (listjcsj_WeiHaiYinSuJianHuYiJu.Any())
                {
                    listjcsj_WeiHaiYinSuJianHuYiJu.ForEach(t => t.WeiHaiYinSuID = jcsj_WeiHaiYinSu.WeiHaiYinSuID);
                    if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).AddRange(listjcsj_WeiHaiYinSuJianHuYiJu) == false)
                    {
                        nret = 1000;
                        strFanHuiZhi = "另存危害因监护依据失败！";
                        goto PROC_EXIT;
                    }
                }

                #endregion

                Data = jcsj_WeiHaiYinSu;


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素组合项目添加
        /// </summary>
        /// <param name="weiHaiYinSuItemAdd"></param>
        /// <returns></returns>
        public string PostWeiHaiYinSuItemAdd(WeiHaiYinSuItemAddClass weiHaiYinSuItemAdd)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                object Data = null;

                #endregion

                #region 验证数据

                if (!weiHaiYinSuItemAdd.Validate(out strFanHuiZhi)) goto PROC_EXIT;

                #endregion

                DbResult<bool> result = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).UseTran(() =>
                {
                    #region 获得岗期和危害因素去先删除

                    if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db)
                    .DeleteWhere(t => t.WeiHaiYinSuID == weiHaiYinSuItemAdd.strWeiHaiYinSuId && t.GangQi == weiHaiYinSuItemAdd.strGangQi) == false)
                    {
                        nret = 1000;
                        strFanHuiZhi = "删除失败！";
                        return;
                    }

                    #endregion

                    #region 准备数据存入数据库

                    List<jcsj_WeiHaiYinSuZuHeXiangMu> listjcsj_WeiHaiYinSuZuHeXiangMu = new List<jcsj_WeiHaiYinSuZuHeXiangMu>();
                    int iShunXu = 1;
                    foreach (ItemAddClass itemAdd in weiHaiYinSuItemAdd.listItem)
                    {
                        jcsj_WeiHaiYinSuZuHeXiangMu jcsj_WeiHaiYinSuZuHeXiangMu = new jcsj_WeiHaiYinSuZuHeXiangMu();

                        #region 验证每一个组合项目的信息

                        if (string.IsNullOrEmpty(itemAdd.strZuHeXiangMuId))
                        {
                            nret = 0;
                            strFanHuiZhi = "组合项目Id为空！";
                            return;
                        }
                        if (string.IsNullOrEmpty(itemAdd.strShiFouBiJian))
                        {
                            nret = 0;
                            strFanHuiZhi = "是否必检为空！";
                            return;
                        }
                        #endregion

                        #region 重复数据跳过进行下一个

                        if (listjcsj_WeiHaiYinSuZuHeXiangMu.Where(t => t.ZuHeXiangMuID == itemAdd.strZuHeXiangMuId).Any())
                        {
                            continue;
                        }

                        #endregion

                        jcsj_WeiHaiYinSuZuHeXiangMu.WeiHaiYinSuID = weiHaiYinSuItemAdd.strWeiHaiYinSuId;
                        jcsj_WeiHaiYinSuZuHeXiangMu.GangQi = weiHaiYinSuItemAdd.strGangQi;
                        jcsj_WeiHaiYinSuZuHeXiangMu.ZuHeXiangMuID = itemAdd.strZuHeXiangMuId;
                        jcsj_WeiHaiYinSuZuHeXiangMu.ShiFouBiJian = itemAdd.strShiFouBiJian;
                        jcsj_WeiHaiYinSuZuHeXiangMu.ShunXu = iShunXu;
                        listjcsj_WeiHaiYinSuZuHeXiangMu.Add(jcsj_WeiHaiYinSuZuHeXiangMu);
                        iShunXu++;
                    }
                    if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).AddRange(listjcsj_WeiHaiYinSuZuHeXiangMu) == false)
                    {
                        nret = 1000;
                        strFanHuiZhi = "保存失败！";
                        return;
                    }

                    #endregion
                },
                (ex) =>
                {
                    nret = 1000;
                    strFanHuiZhi = ex.Message;
                    Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:事务报错异常:【{ex.Message}】");
                });

                #region 返回危害因素组合项目

                Data = new SqlSugarRepository<object>(db).getListBySql($@"select A.*,B.ZuHeXiangMuMingCheng,B.GuoBiaoDaiMa 
from jcsj_WeiHaiYinSuZuHeXiangMu A with(nolock),jcsj_ZuHeXiangMu B with(nolock) 
where A.ZuHeXiangMuID = B.ZuHeXiangMuID
and WeiHaiYinSuID = '{weiHaiYinSuItemAdd.strWeiHaiYinSuId}'
and GangQi = '{weiHaiYinSuItemAdd.strGangQi}'
order by ShunXu");

            #endregion



            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素组合项目修改
        /// </summary>
        /// <param name="weiHaiYinSuItemData"></param>
        /// <returns></returns>
        public string PutWeiHaiYinSuItemUpdate(WeiHaiYinSuItemDataClass weiHaiYinSuItemData)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 验证数据

                if (!weiHaiYinSuItemData.Validate("Update", out strFanHuiZhi)) goto PROC_EXIT;

                #endregion

                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).Update(t => new jcsj_WeiHaiYinSuZuHeXiangMu
                {
                    ShiFouBiJian = weiHaiYinSuItemData.strShiFouBiJian
                }, t => t.WeiHaiYinSuID == weiHaiYinSuItemData.strWeiHaiYinSuId && t.ZuHeXiangMuID == weiHaiYinSuItemData.strZuHeXiangMuId && t.GangQi == weiHaiYinSuItemData.strGangQi) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改失败！";
                    goto PROC_EXIT;
                }

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素组合项目删除
        /// </summary>
        /// <param name="weiHaiYinSuItemData"></param>
        /// <returns></returns>
        public string DeleteWeiHaiYinSuItemDelete(WeiHaiYinSuItemDataClass weiHaiYinSuItemData)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 验证数据

                if (!weiHaiYinSuItemData.Validate("Update", out strFanHuiZhi)) goto PROC_EXIT;

                #endregion

                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db)
                    .DeleteWhere(t => t.WeiHaiYinSuID == weiHaiYinSuItemData.strWeiHaiYinSuId && t.ZuHeXiangMuID == weiHaiYinSuItemData.strZuHeXiangMuId && t.GangQi == weiHaiYinSuItemData.strGangQi) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = $@"删除失败！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).Update(t => new jcsj_WeiHaiYinSuZuHeXiangMu
                {
                    ShunXu = t.ShunXu - 1
                }, t => t.WeiHaiYinSuID == weiHaiYinSuItemData.strWeiHaiYinSuId && t.GangQi == weiHaiYinSuItemData.strGangQi && t.ShunXu > weiHaiYinSuItemData.iShunXu) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = $@"修改失败！";
                    goto PROC_EXIT;
                }

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素组合项目调整顺序
        /// </summary>
        /// <param name="weiHaiYinSuItemShunXu"></param>
        /// <returns></returns>
        public string PutWeiHaiYinSuItemTiaoZhengShunXu(WeiHaiYinSuItemShunXuClass weiHaiYinSuItemShunXu)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                Expression<Func<jcsj_WeiHaiYinSuZuHeXiangMu, jcsj_WeiHaiYinSuZuHeXiangMu>> columns;
                Expression<Func<jcsj_WeiHaiYinSuZuHeXiangMu, bool>> expression;

                #endregion

                #region 调整顺序

                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).Update(t => new jcsj_WeiHaiYinSuZuHeXiangMu
                {
                    ShunXu = weiHaiYinSuItemShunXu.iTiaoZhengHouShunXu
                }, t => t.WeiHaiYinSuID == weiHaiYinSuItemShunXu.strWeiHaiYinSuId && t.ZuHeXiangMuID == weiHaiYinSuItemShunXu.strZuHeXiangMuId
                && t.GangQi == weiHaiYinSuItemShunXu.strGangQi) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改顺序失败！";
                    goto PROC_EXIT;
                }
                if (weiHaiYinSuItemShunXu.iTiaoZhengQianShunXu < weiHaiYinSuItemShunXu.iTiaoZhengHouShunXu)
                {
                    columns = t => new jcsj_WeiHaiYinSuZuHeXiangMu
                    {
                        ShunXu = t.ShunXu - 1
                    };
                    expression = t => t.ShunXu >= weiHaiYinSuItemShunXu.iTiaoZhengQianShunXu && t.ShunXu <= weiHaiYinSuItemShunXu.iTiaoZhengHouShunXu
                    && t.WeiHaiYinSuID == weiHaiYinSuItemShunXu.strWeiHaiYinSuId && t.GangQi == weiHaiYinSuItemShunXu.strGangQi && t.ZuHeXiangMuID != weiHaiYinSuItemShunXu.strZuHeXiangMuId;
                }
                else if (weiHaiYinSuItemShunXu.iTiaoZhengQianShunXu > weiHaiYinSuItemShunXu.iTiaoZhengHouShunXu)
                {
                    columns = t => new jcsj_WeiHaiYinSuZuHeXiangMu
                    {
                        ShunXu = t.ShunXu + 1
                    };
                    expression = t => t.ShunXu <= weiHaiYinSuItemShunXu.iTiaoZhengQianShunXu && t.ShunXu >= weiHaiYinSuItemShunXu.iTiaoZhengHouShunXu
                    && t.WeiHaiYinSuID == weiHaiYinSuItemShunXu.strWeiHaiYinSuId && t.GangQi == weiHaiYinSuItemShunXu.strGangQi && t.ZuHeXiangMuID != weiHaiYinSuItemShunXu.strZuHeXiangMuId;
                }
                else
                {
                    nret = 1;
                    strFanHuiZhi = "调整前后顺序一致！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).Update(columns, expression) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改顺序失败！";
                    goto PROC_EXIT;
                }

            #endregion


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素监护依据新增
        /// </summary>
        /// <param name="weiHaiYinSuJianHuYiJuAdd"></param>
        /// <param name="strYuanQuQianZhui"></param>
        /// <returns></returns>
        public string PostWeiHaiYinSuJianHuYiJuAdd(WeiHaiYinSuJianHuYiJuAddClass weiHaiYinSuJianHuYiJuAdd, string strYuanQuQianZhui)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                int iShunXu = 0;
                int itid = 0;
                string strSql = "";
                object Data = null;

                #endregion

                #region 验证数据

                if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuJianHuYiJuAdd.strWeiHaiYinSuId
                    && t.JianHuYiJuMingCheng == weiHaiYinSuJianHuYiJuAdd.strJianHuYiJuMingCheng).Any())
                {
                    nret = 1;
                    strFanHuiZhi = $@"当前监护依据【{weiHaiYinSuJianHuYiJuAdd.strJianHuYiJuMingCheng}】已经存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 保存数据

                DbResult<bool> result = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).UseTran(() =>
                {
                    var ShunXu = new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuJianHuYiJuAdd.strWeiHaiYinSuId);
                    if (ShunXu.Any())
                    {
                        iShunXu = ShunXu.Max(t => t.ShunXu) + 1;
                    }
                    else
                    {
                        iShunXu = 1;
                    }
                    jcsj_WeiHaiYinSuJianHuYiJu jcsj_WeiHaiYinSuJianHuYiJu = new jcsj_WeiHaiYinSuJianHuYiJu();
                    jcsj_WeiHaiYinSuJianHuYiJu.WeiHaiYinSuID = weiHaiYinSuJianHuYiJuAdd.strWeiHaiYinSuId;
                    jcsj_WeiHaiYinSuJianHuYiJu.JianHuYiJuMingCheng = weiHaiYinSuJianHuYiJuAdd.strJianHuYiJuMingCheng;
                    jcsj_WeiHaiYinSuJianHuYiJu.ShunXu = iShunXu;
                    itid = new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).AddReturnIdentity(jcsj_WeiHaiYinSuJianHuYiJu);
                    strSql = $@"update jcsj_WeiHaiYinSuJianHuYiJu set JianHuYiJuID = '{strYuanQuQianZhui + itid}' where tid = '{itid}'";
                    if (new SqlSugarRepository<object>(db).ExecuteCommandSql(strSql) == false)
                    {
                        nret = 1000;
                        strFanHuiZhi = "保存危害因素失败！"; return;
                    }
                    jcsj_WeiHaiYinSuJianHuYiJu.tid = itid;
                    jcsj_WeiHaiYinSuJianHuYiJu.JianHuYiJuID = strYuanQuQianZhui + itid;
                    Data = jcsj_WeiHaiYinSuJianHuYiJu;
                },
                 (ex) =>
                 {
                     nret = 1000;
                     strFanHuiZhi = ex.Message;
                     Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:事务报错异常:【{ex.Message}】");
                 });


            #endregion

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素监护依据修改
        /// </summary>
        /// <param name="weiHaiYinSuJianHuYiJuData"></param>
        /// <returns></returns>
        public string PutWeiHaiYinSuJianHuYiJuUpdate(WeiHaiYinSuJianHuYiJuDataClass weiHaiYinSuJianHuYiJuData)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                object Data = null;
                List<jcsj_WeiHaiYinSuJianHuYiJu> listjcsj_WeiHaiYinSuJianHuYiJu = new List<jcsj_WeiHaiYinSuJianHuYiJu>();

                #endregion

                #region 验证数据

                if (!weiHaiYinSuJianHuYiJuData.Validate("Update", out strFanHuiZhi)) goto PROC_EXIT;
                listjcsj_WeiHaiYinSuJianHuYiJu = new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).getByWhere(t => t.JianHuYiJuID == weiHaiYinSuJianHuYiJuData.strJianHuYiJuID);
                if (listjcsj_WeiHaiYinSuJianHuYiJu.Any() == false)
                {
                    nret = 1;
                    strFanHuiZhi = $@"未发现监护依据ID为【{weiHaiYinSuJianHuYiJuData.strJianHuYiJuID}】的记录！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).getByWhere(t => t.WeiHaiYinSuID == weiHaiYinSuJianHuYiJuData.strWeiHaiYinSuId
                && t.JianHuYiJuMingCheng == weiHaiYinSuJianHuYiJuData.strJianHuYiJuMingCheng).Any())
                {
                    nret = 1;
                    strFanHuiZhi = $@"监护依据【{weiHaiYinSuJianHuYiJuData.strJianHuYiJuMingCheng}】已经在此危害因素下存在！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 修改

                if (new SqlSugarRepository<object>(db)
                    .ExecuteCommandSql($@"update jcsj_WeiHaiYinSuJianHuYiJu set JianHuYiJuMingCheng = '{weiHaiYinSuJianHuYiJuData.strJianHuYiJuMingCheng}' 
where JianHuYiJuID = '{weiHaiYinSuJianHuYiJuData.strJianHuYiJuID}'") == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改危害因素监护依据失败";
                    goto PROC_EXIT;
                }

                #endregion

                listjcsj_WeiHaiYinSuJianHuYiJu[0].JianHuYiJuMingCheng = weiHaiYinSuJianHuYiJuData.strJianHuYiJuMingCheng;
                Data = listjcsj_WeiHaiYinSuJianHuYiJu[0];

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素监护依据删除
        /// </summary>
        /// <param name="weiHaiYinSuJianHuYiJuData"></param>
        /// <returns></returns>
        public string DeleteWeiHaiYinSuJianHuYiJuDelete(WeiHaiYinSuJianHuYiJuDataClass weiHaiYinSuJianHuYiJuData)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                object Data = null;

                #endregion

                #region 验证数据

                if (!weiHaiYinSuJianHuYiJuData.Validate("Delete", out strFanHuiZhi)) goto PROC_EXIT;

                #endregion

                #region 执行删除

                if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).DeleteWhere(t => t.JianHuYiJuID == weiHaiYinSuJianHuYiJuData.strJianHuYiJuID) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "删除失败！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).Update(t => new jcsj_WeiHaiYinSuJianHuYiJu
                {
                    ShunXu = t.ShunXu - 1
                }, t => t.ShunXu > weiHaiYinSuJianHuYiJuData.iShunXu) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "处理顺序失败！";
                    goto PROC_EXIT;
                }

                #endregion

                Data = weiHaiYinSuJianHuYiJuData.strJianHuYiJuID;

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素监护依据调整顺序
        /// </summary>
        /// <param name="weiHaiYinSuJianHuYiJuShunXu"></param>
        /// <returns></returns>
        public string PutWeiHaiYinSuJianHuYiJuTiaoZhengShunXu(WeiHaiYinSuJianHuYiJuShunXuClass weiHaiYinSuJianHuYiJuShunXu)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                Expression<Func<jcsj_WeiHaiYinSuJianHuYiJu, jcsj_WeiHaiYinSuJianHuYiJu>> columns;
                Expression<Func<jcsj_WeiHaiYinSuJianHuYiJu, bool>> expression;

                #endregion

                #region 调整顺序

                if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).Update(t => new jcsj_WeiHaiYinSuJianHuYiJu
                {
                    ShunXu = weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengHouShunXu
                }, t => t.WeiHaiYinSuID == weiHaiYinSuJianHuYiJuShunXu.strWeiHaiYinSuId && t.JianHuYiJuID == weiHaiYinSuJianHuYiJuShunXu.strJianHuYiJuID) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改顺序失败！";
                    goto PROC_EXIT;
                }
                if (weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengQianShunXu < weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengHouShunXu)
                {
                    columns = t => new jcsj_WeiHaiYinSuJianHuYiJu
                    {
                        ShunXu = t.ShunXu - 1
                    };
                    expression = t => t.ShunXu >= weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengQianShunXu && t.ShunXu <= weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengHouShunXu
                    && t.WeiHaiYinSuID == weiHaiYinSuJianHuYiJuShunXu.strWeiHaiYinSuId && t.JianHuYiJuID != weiHaiYinSuJianHuYiJuShunXu.strJianHuYiJuID;
                }
                else if (weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengQianShunXu > weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengHouShunXu)
                {
                    columns = t => new jcsj_WeiHaiYinSuJianHuYiJu
                    {
                        ShunXu = t.ShunXu - 1
                    };
                    expression = t => t.ShunXu <= weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengQianShunXu && t.ShunXu >= weiHaiYinSuJianHuYiJuShunXu.iTiaoZhengHouShunXu
                    && t.WeiHaiYinSuID == weiHaiYinSuJianHuYiJuShunXu.strWeiHaiYinSuId && t.JianHuYiJuID != weiHaiYinSuJianHuYiJuShunXu.strJianHuYiJuID;
                }
                else
                {
                    nret = 1;
                    strFanHuiZhi = "调整前后顺序一致！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuJianHuYiJu>(db).Update(columns, expression) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "修改顺序失败！";
                    goto PROC_EXIT;
                }

            #endregion

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = ""
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素统一更换组合项目
        /// </summary>
        /// <param name="weiHaiYinSuGengHuanXiangMu"></param>
        /// <returns></returns>
        public string PutWeiHuanYinSuTongYiGengHuanItem(WeiHaiYinSuTongYiGengHuanItemClass weiHaiYinSuTongYiGengHuanItem)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                List<string> listGangQi = new List<string>()
                {
                    "上岗前","在岗期间","离岗时","离岗后","应急"
                };
                string strSql = "";
                object Data = null;

                #endregion

                #region 验证数据

                if (!weiHaiYinSuTongYiGengHuanItem.Validate(out strFanHuiZhi)) goto PROC_EXIT;
                if (new SqlSugarRepository<jcsj_ZuHeXiangMu>(db).getByWhere(t => t.ZuHeXiangMuID == weiHaiYinSuTongYiGengHuanItem.strTiaoZhengHouZuheXiangMuId).Any() == false)
                {
                    nret = 1;
                    strFanHuiZhi = $@"为发现调整后组合项目Id【{weiHaiYinSuTongYiGengHuanItem.strTiaoZhengHouZuheXiangMuId}】！";
                    goto PROC_EXIT;
                }

                #endregion

                #region 执行操作

                DbResult<bool> result = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).UseTran(() =>
                {
                    foreach (var GangQi in listGangQi)
                    {
                        strSql = $@"delete from jcsj_WeiHaiYinSuZuHeXiangMu where ZuHeXiangMuID = '{weiHaiYinSuTongYiGengHuanItem.strTiaoZhengHouZuheXiangMuId}' and GangQi='{GangQi}' and WeiHaiYinSuID in 
(select distinct WeiHaiYinSuID from jcsj_WeiHaiYinSuZuHeXiangMu with(nolock) where ZuHeXiangMuID = '{weiHaiYinSuTongYiGengHuanItem.strTiaoZhengQianZuheXiangMuId}' and GangQi='{GangQi}')";
                        if (new SqlSugarRepository<object>(db).ExecuteCommandSql(strSql) == false)
                        {
                            nret = 1000;
                            strFanHuiZhi = "删除操作失败！";
                            return;
                        }
                    }
                    strSql = $@"update jcsj_WeiHaiYinSuZuHeXiangMu set ZuHeXiangMuID = '{weiHaiYinSuTongYiGengHuanItem.strTiaoZhengHouZuheXiangMuId}'
where ZuHeXiangMuID = '{weiHaiYinSuTongYiGengHuanItem.strTiaoZhengQianZuheXiangMuId}'";
                    if (new SqlSugarRepository<object>(db).ExecuteCommandSql(strSql) == false)
                    {
                        nret = 1000;
                        strFanHuiZhi = "修改操作失败！";
                        return;
                    }
                },
              (ex) =>
              {
                  nret = 1000;
                  strFanHuiZhi = ex.Message;
                  Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:事务报错异常:【{ex.Message}】");
              });

                #endregion

                Data = new SqlSugarRepository<object>(db).getListBySql($@"select top 1 A.*,B.ZuHeXiangMuMingCheng,B.GuoBiaoDaiMa 
from jcsj_WeiHaiYinSuZuHeXiangMu A with(nolock),jcsj_ZuHeXiangMu B with(nolock) 
where A.ZuHeXiangMuID = B.ZuHeXiangMuID
and B.ZuHeXiangMuID = '{weiHaiYinSuTongYiGengHuanItem.strTiaoZhengHouZuheXiangMuId}' 
order by ShunXu");

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素统一添加组合项目
        /// </summary>
        /// <param name="weiHaiYinSuTongYiItem"></param>
        /// <returns></returns>
        public string PostWeiHaiYinSuTongYiAddItem(WeiHaiYinSuTongYiItemClass weiHaiYinSuTongYiItem)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                List<string> listGangQi = new List<string>()
                {
                    "上岗前","在岗期间","离岗时","离岗后","应急"
                };
                List<jcsj_WeiHaiYinSu> litsjcsj_WeiHaiYinSu;
                List<jcsj_WeiHaiYinSuZuHeXiangMu> listjcsj_WeiHaiYinSuZuHeXiangMu;
                List<jcsj_WeiHaiYinSuZuHeXiangMu> listjcsj_WeiHaiYinSuZuHeXiangMuAdd = new List<jcsj_WeiHaiYinSuZuHeXiangMu>();
                object Data = null;
                int iShunXu = 1;

                #endregion

                #region 添加危害因素对应项目

                litsjcsj_WeiHaiYinSu = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getAll();
                listjcsj_WeiHaiYinSuZuHeXiangMu = new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).getAll();
                foreach (var jcsj_WeiHaiYinSu in litsjcsj_WeiHaiYinSu)
                {
                    foreach (var GangQi in listGangQi)
                    {
                        var WeiHaiYinSuZuHeXiangMu = listjcsj_WeiHaiYinSuZuHeXiangMu.Where(t => t.GangQi == GangQi && t.WeiHaiYinSuID == jcsj_WeiHaiYinSu.WeiHaiYinSuID);
                        if (WeiHaiYinSuZuHeXiangMu.Any())
                        {
                            if (WeiHaiYinSuZuHeXiangMu.Where(t => t.ZuHeXiangMuID == weiHaiYinSuTongYiItem.strZuheXiangMuId).Any())
                            {
                                continue;
                            }
                            iShunXu = WeiHaiYinSuZuHeXiangMu.Max(t => t.ShunXu) + 1;
                        }
                        else
                        {
                            iShunXu = 1;
                        }
                        jcsj_WeiHaiYinSuZuHeXiangMu jcsj_WeiHaiYinSuZuHeXiangMu = new jcsj_WeiHaiYinSuZuHeXiangMu();
                        jcsj_WeiHaiYinSuZuHeXiangMu.WeiHaiYinSuID = jcsj_WeiHaiYinSu.WeiHaiYinSuID;
                        jcsj_WeiHaiYinSuZuHeXiangMu.GangQi = GangQi;
                        jcsj_WeiHaiYinSuZuHeXiangMu.ZuHeXiangMuID = weiHaiYinSuTongYiItem.strZuheXiangMuId;
                        jcsj_WeiHaiYinSuZuHeXiangMu.ShiFouBiJian = "是";
                        jcsj_WeiHaiYinSuZuHeXiangMu.ShunXu = iShunXu;
                        listjcsj_WeiHaiYinSuZuHeXiangMuAdd.Add(jcsj_WeiHaiYinSuZuHeXiangMu);
                    }
                }
                if (listjcsj_WeiHaiYinSuZuHeXiangMuAdd.Count == 0)
                {
                    nret = 1;
                    strFanHuiZhi = "所有危害因素的岗期下已经存在此组合项目！";
                    goto PROC_EXIT;
                }
                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).AddRange(listjcsj_WeiHaiYinSuZuHeXiangMuAdd) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "添加项目失败！";
                    goto PROC_EXIT;
                }

                #endregion

                Data = new SqlSugarRepository<object>(db).getListBySql($@"select top 1 A.*,B.ZuHeXiangMuMingCheng,B.GuoBiaoDaiMa 
from jcsj_WeiHaiYinSuZuHeXiangMu A with(nolock),jcsj_ZuHeXiangMu B with(nolock) 
where A.ZuHeXiangMuID = B.ZuHeXiangMuID
and B.ZuHeXiangMuID = '{weiHaiYinSuTongYiItem.strZuheXiangMuId}' 
order by ShunXu");


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 危害因素统一删除组合项目
        /// </summary>
        /// <param name="weiHaiYinSuTongYiItem"></param>
        /// <returns></returns>
        public string DeleteWeiHaiYinSuTongYiDeleteItem(WeiHaiYinSuTongYiItemClass weiHaiYinSuTongYiItem)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                object Data = null;

                #endregion

                #region 删除项目

                if (new SqlSugarRepository<jcsj_WeiHaiYinSuZuHeXiangMu>(db).DeleteWhere(t => t.ZuHeXiangMuID == weiHaiYinSuTongYiItem.strZuheXiangMuId) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "删除失败！";
                    goto PROC_EXIT;
                }

                #endregion

                Data = weiHaiYinSuTongYiItem.strZuheXiangMuId;

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 国标对应本地组合项目添加
        /// </summary>
        /// <param name="weiHaiYinSuDuiYinBenDiItem"></param>
        /// <returns></returns>
        public string PostGuoBiaoDuiYinBenDiItemAdd(WeiHaiYinSuDuiYinBenDiItemAddClass weiHaiYinSuDuiYinBenDiItemAdd)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                object Data = null;
                List<GBZ_GuoBiaoDuiYingBenDi> listGBZ_GuoBiaoDuiYingBenDi = new List<GBZ_GuoBiaoDuiYingBenDi>();

                #endregion

                #region 验证数据

                if (!weiHaiYinSuDuiYinBenDiItemAdd.Validate(out strFanHuiZhi)) goto PROC_EXIT;
                if (new SqlSugarRepository<GBZ_GuoBiaoDuiYingBenDi>(db)
                    .DeleteWhere(t => t.GuoBiaoZuHeXiangMuDaiMa == weiHaiYinSuDuiYinBenDiItemAdd.strGuoBiaoItemId) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "删除失败！";
                    goto PROC_EXIT;
                }

                #endregion

                foreach (var item in weiHaiYinSuDuiYinBenDiItemAdd.listBenDiItemId)
                {
                    if (listGBZ_GuoBiaoDuiYingBenDi.Where(t => t.BenDuiZuHeXiangMuID == item).Any())
                    {
                        continue;
                    }
                    GBZ_GuoBiaoDuiYingBenDi gbZ_GuoBiaoDuiYingBenDi = new GBZ_GuoBiaoDuiYingBenDi();
                    gbZ_GuoBiaoDuiYingBenDi.GuoBiaoZuHeXiangMuDaiMa = weiHaiYinSuDuiYinBenDiItemAdd.strGuoBiaoItemId;
                    gbZ_GuoBiaoDuiYingBenDi.BenDuiZuHeXiangMuID = item;
                    listGBZ_GuoBiaoDuiYingBenDi.Add(gbZ_GuoBiaoDuiYingBenDi);
                }
                if (new SqlSugarRepository<GBZ_GuoBiaoDuiYingBenDi>(db).AddRange(listGBZ_GuoBiaoDuiYingBenDi) == false)
                {
                    nret = 1000;
                    strFanHuiZhi = "添加失败！";
                    goto PROC_EXIT;
                }

                Data = new SqlSugarRepository<object>(db).getListBySqlQuery($@"select B.ZuHeXiangMuID,B.ZuHeXiangMuMingCheng from GBZ_GuoBiaoDuiYingBenDi A with(nolock),jcsj_ZuHeXiangMu B with(nolock)
where A.BenDuiZuHeXiangMuID = B.ZuHeXiangMuID and A.GuoBiaoZuHeXiangMuDaiMa = '{weiHaiYinSuDuiYinBenDiItemAdd.strGuoBiaoItemId}'");


            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 国标对应本地组合项目删除
        /// </summary>
        /// <param name="weiHaiYinSuDuiYinBenDiItem"></param>
        /// <returns></returns>
        public string DeleteGuoBiaoDuiYinBenDiItemDelete(WeiHaiYinSuDuiYinBenDiItemDeleteClass weiHaiYinSuDuiYinBenDiItemDelete)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                object Data = null;

                #endregion

                #region 执行删除操作

                if (new SqlSugarRepository<GBZ_GuoBiaoDuiYingBenDi>(db).DeleteWhere(t => t.GuoBiaoZuHeXiangMuDaiMa == weiHaiYinSuDuiYinBenDiItemDelete.strGuoBiaoItemId
                    && t.BenDuiZuHeXiangMuID == weiHaiYinSuDuiYinBenDiItemDelete.strBenDiItemId) == false)
                {
                    nret = 1;
                    strFanHuiZhi = "删除失败！";
                    goto PROC_EXIT;
                }

                #endregion

                Data = weiHaiYinSuDuiYinBenDiItemDelete.strBenDiItemId;

            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = Data
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
        /// <summary>
        /// 分析危害因素
        /// </summary>
        /// <param name="strWeiHaiYinSuId"></param>
        /// <param name="strGangQi"></param>
        /// <returns></returns>
        public string GetFenXiWeiHaiYinSu(string? strWeiHaiYinSuId, string? strGangQi)
        {
            int nret = 0; string strFanHuiZhi = "";
            try
            {
                Logger.Singleton.Debug($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】");

                #region 声明变量

                List<GBZ_GuoBiaoDuiYingBenDi> listGBZ_GuoBiaoDuiYingBenDi;
                List<GBZ_WeiHaiYinSuXiangMu> listGBZ_WeiHaiYinSuXiangMu;
                List<jcsj_WeiHaiYinSu> listjcsj_WeiHaiYinSu;
                DataTable dtJianSuoWeiHaiYinSu;
                string strSql = "";
                StringBuilder strData = new StringBuilder();

                #endregion

                #region 准备数据

                listGBZ_GuoBiaoDuiYingBenDi = new SqlSugarRepository<GBZ_GuoBiaoDuiYingBenDi>(db).getAll();
                listGBZ_WeiHaiYinSuXiangMu = new SqlSugarRepository<GBZ_WeiHaiYinSuXiangMu>(db).getAll();
                listjcsj_WeiHaiYinSu = new SqlSugarRepository<jcsj_WeiHaiYinSu>(db).getAll();
                if (string.IsNullOrEmpty(strWeiHaiYinSuId) && string.IsNullOrEmpty(strGangQi))
                {
                    strSql = $@"select * from jcsj_WeiHaiYinSuZuHeXiangMu A with (nolock),jcsj_WeiHaiYinSu B with (nolock) 
where A.WeiHaiYinSuID = B.WeiHaiYinSuID
order  by GangQi,A.WeiHaiYinSuID";
                }
                else
                {
                    strSql = $@"select * from jcsj_WeiHaiYinSuZuHeXiangMu A with (nolock),jcsj_WeiHaiYinSu B with (nolock) 
where A.WeiHaiYinSuID = B.WeiHaiYinSuID
and  A.WeiHaiYinSuID='{strWeiHaiYinSuId}' and GangQi='{strGangQi}'";
                }
                dtJianSuoWeiHaiYinSu = new SqlSugarRepository<object>(db).getDataTableBySqlQuery(strSql);

                #endregion

                #region 检索处理

                var GangQiWeiHaiYinSu = dtJianSuoWeiHaiYinSu.AsEnumerable()
                       .Where(row => string.IsNullOrEmpty(row.Field<string>("GuoBiaoDaiMa")) == false)
                       .Select(row => new
                       {
                           WeiHaiYinSuMingCheng = row.Field<string>("WeiHaiYinSuMingCheng"),
                           WeiHaiYinSuZhongLei = row.Field<string>("WeiHaiYinSuZhongLei"),
                           GuoBiaoDaiMa = row.Field<string>("GuoBiaoDaiMa"),
                           GangQi = row.Field<string>("GangQi")
                       })
                       .OrderBy(row => row.GangQi)
                       .ThenBy(row => row.WeiHaiYinSuZhongLei)
                       .Distinct();

                foreach (var item in GangQiWeiHaiYinSu)
                {
                    if (listGBZ_WeiHaiYinSuXiangMu.Any(t => t.GangQi == item.GangQi && t.WeiHaiYinSuBianMa == item.GuoBiaoDaiMa) == false)
                    {
                        continue;
                    }
                    var GuoBiaoItemes = listGBZ_WeiHaiYinSuXiangMu.Where(t => t.GangQi == item.GangQi && t.WeiHaiYinSuBianMa == item.GuoBiaoDaiMa);
                    var WeiHaiYinSuDuiYinItem = dtJianSuoWeiHaiYinSu.AsEnumerable()
                        .Where(row => row.Field<string>("GangQi") == item.GangQi && row.Field<string>("GuoBiaoDaiMa") == item.GuoBiaoDaiMa).CopyToDataTable();
                    foreach (var GuoBiaoItem in GuoBiaoItemes)
                    {
                        List<string> listDuiYinBenDiId = listGBZ_GuoBiaoDuiYingBenDi
                            .Where(t => t.GuoBiaoZuHeXiangMuDaiMa == GuoBiaoItem.ZuHeXiangMuBianMa)
                            .Select(t => t.BenDuiZuHeXiangMuID)
                            .ToList();
                        if (strData.ToString().Contains($"【{item.GangQi}】危害因素检索结果：") == false)
                        {
                            strData.AppendLine($"【{item.GangQi}】危害因素检索结果：");

                            #region 验证危害因素

                            List<string?> list国标代码为空的危害因素 = dtJianSuoWeiHaiYinSu.AsEnumerable()
                                .Where(row => string.IsNullOrEmpty(row.Field<string>("GuoBiaoDaiMa")) == true && row.Field<string>("GangQi") == item.GangQi)
                                .Select(row => row.Field<string>("WeiHaiYinSuMingCheng"))
                                .Distinct()
                                .ToList();
                            List<string> list国标代码不存在的危害因素 = listGBZ_WeiHaiYinSuXiangMu
                                .Where(t => t.GangQi == item.GangQi && t.WeiHaiYinSuBianMa == item.GuoBiaoDaiMa)
                                .Select(t => t.WeiHaiYinSuMingCheng)
                                .Distinct()
                                .ToList();
                            List<string> list不存在对应项目的危害因素 = listjcsj_WeiHaiYinSu.
                                Where(t => dtJianSuoWeiHaiYinSu.AsEnumerable().Where(dr => dr.Field<string>("GangQi") == item.GangQi).Select(dr => dr.Field<string>("WeiHaiYinSuID")).Distinct()
                                .Contains(t.WeiHaiYinSuID) == false)
                                .Select(t => t.WeiHaiYinSuMingCheng)
                                .ToList();

                            if (list国标代码为空的危害因素.Count != 0)
                            {
                                strData.AppendLine($"\t国标代码为空危害因素：{string.Join("、", list国标代码为空的危害因素)}");
                            }
                            if (list国标代码不存在的危害因素.Count == 0)
                            {
                                strData.AppendLine($"\t国标代码不存在危害因素：{string.Join("、", list国标代码不存在的危害因素)}");
                            }
                            if (list不存在对应项目的危害因素.Count != 0 && string.IsNullOrEmpty(strWeiHaiYinSuId) == true && string.IsNullOrEmpty(strGangQi) == true)
                            {
                                strData.AppendLine($"\t不存在对应项目的危害因素：{string.Join("、", list不存在对应项目的危害因素)}");
                            }

                            #endregion

                        }
                        if (listDuiYinBenDiId.Count != 0)
                        {
                            if (WeiHaiYinSuDuiYinItem.AsEnumerable()
                                .Any(row => row.Field<string>("GangQi") == item.GangQi && row.Field<string>("WeiHaiYinSuMingCheng") == item.WeiHaiYinSuMingCheng
                                && listDuiYinBenDiId.Contains(row.Field<string>("ZuHeXiangMuID"))) == false)
                            {
                                strData.AppendLine($"\t种类：【{item.WeiHaiYinSuZhongLei}】危害因素：【{item.WeiHaiYinSuMingCheng}】缺少国标组合项目：【{GuoBiaoItem.ZuHeXiangMuMingCheng}】");
                            }
                            else if (WeiHaiYinSuDuiYinItem.AsEnumerable()
                                .Where(row => row.Field<string>("GangQi") == item.GangQi && row.Field<string>("WeiHaiYinSuMingCheng") == item.WeiHaiYinSuMingCheng
                                && listDuiYinBenDiId.Contains(row.Field<string>("ZuHeXiangMuID"))).ToList().Count > 1)
                            {
                                strData.AppendLine($"\t种类：【{item.WeiHaiYinSuZhongLei}】危害因素：【{item.WeiHaiYinSuMingCheng}】对应的国标组合项目：【{GuoBiaoItem.ZuHeXiangMuMingCheng}】大于一个");
                            }
                        }

                    }
                }


                #region 检索国标组合对应本地为空的数据

                if (string.IsNullOrEmpty(strWeiHaiYinSuId) && string.IsNullOrEmpty(strGangQi))
                {
                    List<string> list国标组合对应本地为空 = listGBZ_WeiHaiYinSuXiangMu
                   .Where(t => listGBZ_GuoBiaoDuiYingBenDi
                                   .Select(t => t.GuoBiaoZuHeXiangMuDaiMa).Contains(t.ZuHeXiangMuBianMa) == false)
                   .Select(t => t.ZuHeXiangMuMingCheng)
                   .Distinct()
                   .ToList();
                    if (list国标组合对应本地为空.Count != 0)
                    {
                        strData.AppendLine($"\r\n国标组合对应本地为空的国标组合项目：{string.Join("、", list国标组合对应本地为空)}");
                    }
                }

            #endregion

            #endregion



            PROC_EXIT:
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = nret,
                    Message = strFanHuiZhi,
                    Data = strData
                });
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error($@"【{System.Reflection.MethodBase.GetCurrentMethod().Name}】:报错异常:" + ex.Message);
                return JsonConvert.SerializeObject(new ApiResult<object>()
                {
                    Success = 1000,
                    Message = ex.Message,
                    Data = ""
                });
            }
        }
    }
}
